﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace JiveMessenger.ValidationRules
{
    public class MessageAgeValidation : ValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            int maxAgeInHours = 48;
            if (value is string)
            {
                int number;
                if (!Int32.TryParse((value as string), out number))
                    return new ValidationResult(false, "Please enter a valid number");
                else if (number < 1)
                    return new ValidationResult(false, "Value must be at least 1");
                else if (number > maxAgeInHours)
                    return new ValidationResult(false, string.Format("Maximum value is {0}",maxAgeInHours));
            }
            return ValidationResult.ValidResult;
        }
    }
}
